#include "util.h"

std::string Util::GetFileContents( std::string name )
{
	
	std::ifstream f( name.c_str() );
	std::string contents = "";
	
	f.seekg( 0, std::ios::end );
	contents.resize( f.tellg() );
	f.seekg( 0, std::ios::beg );
	
	f.read( &contents[0], contents.length() );
	
	f.close();
	
	return contents;
	
}

double Util::GetDistance( double x1, double y1, double x2, double y2 )
	{
	
		double dx = fabs( x1 - x2 );
		double dy = fabs( y1 - y2 );
		
		return sqrt( ( dx * dx ) + ( dy * dy ) );
		
	}
	
	
int Util::random( int min, int max )
{
	
	return ( ( int )rand() % ( max - min ) + 1 ) + min;
	
}
	
bool Util::DoesFileExist( const char * s )
{
	
	std::ifstream f( s );
	bool b = true;
	
	if( !f )
	{
		
		b = false;
		
	}
	
	f.close();
	
	return b;
	
}

int Util::RoundToPower( int number, int power )
{
	
	int t = 1;
	
	while( t < number )
	{
		
		t *= power;
	}
	
	return t;
	
}